/**
 * Copyright (c) 2018 软唐 All rights reserved.
 * <p>
 * https://www.softtown.cn
 * <p>
 * 版权所有，侵权必究！
 */

package com.softtown.modules.message.sms;

import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.softtown.common.constant.Constant;
import com.softtown.common.exception.ErrorCode;
import com.softtown.common.exception.RenException;
import com.softtown.common.utils.HttpUtils;
import com.softtown.common.utils.SpringContextUtils;
import com.softtown.modules.message.service.SysSmsService;
import com.softtown.modules.security.entity.SysSmsContentEntity;
import java.io.IOException;
import java.util.Arrays;
import net.sf.json.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 阿里云第三方短信服务
 *
 * @author Ding Ya Yong
 */
public class AliThirdSmsService extends AbstractSmsService {



    public AliThirdSmsService(SmsConfig config) {
        this.config = config;
    }


    @Override
    public void sendSms(String mobile, LinkedHashMap<String, String> params) {
        this.sendSms(mobile, params, config.getAliyunSignName(), config.getAliyunTemplateCode());
    }

    @Override
    public void sendSms(String mobile, LinkedHashMap<String, String> params, String signName, String template) {
    }

    @Override
    public String sendSmsByLogin(String mobile,String skin,String smsCode) {
        String jsonString ="";
        try {
            HttpResponse response = HttpUtils.doGet(smsCode, mobile, skin,config.getSign(),config.getAppCode(),config.getHost(),config.getPath());
            jsonString = EntityUtils.toString(response.getEntity());
        } catch (Exception ioException) {

            ioException.printStackTrace();
        }
        return jsonString;
    }
}
